package com.kmxd.ams.core.common.enums;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.kmxd.ams.core.common.constant.ErrorCode;
import com.kmxd.ams.core.exception.BizException;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * CATALOG
 *
 * @author nickbi
 */
@Getter
@AllArgsConstructor
public enum StatAnnualTypeEnum {

  /** 本单位填报 */
  SELF_UNIT(1, "本单位填报"),
  /** 下级单位 */
  SUB_UNIT(2, "下级单位填报"),
  SUMMARY(3, "汇总年报");

  private Integer code;
  private String desc;

  public static StatAnnualTypeEnum convert(Integer type) {
    return Arrays.stream(values())
        .filter(x -> x.code.equals(type))
        .findAny()
        .orElseThrow(() -> BizException.instance(ErrorCode.NOT_FOUND, "未找到档案状态：" + type));
  }

  @JsonCreator
  public static StatAnnualTypeEnum getValue(Integer type) {
    return Arrays.stream(values()).filter(x -> Objects.equals(x.code, type)).findAny().orElse(null);
  }
}
